<?php


namespace api\controller;

use common\controller\VerifyController;
use common\service\ProjectStepCategoryConfirmConfigService;
use think\Request;
use think\Response;

/**
 * 项目环节确认配置控制器
 */
class ProjectStepCategoryConfirmConfigController extends VerifyController
{
    /** @var ProjectStepCategoryConfirmConfigService $projectStepCategoryConfirmConfigService */
    private $projectStepCategoryConfirmConfigService;

    /**
     *
     */
    public function __construct()
    {
        parent::__construct();
        $this->projectStepCategoryConfirmConfigService = ProjectStepCategoryConfirmConfigService::getInstance();
    }

    /**
     * 保存配置
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function save(Request $request)
    {
        $res = $this->projectStepCategoryConfirmConfigService->save($request->param()['data']);
        return json(success_response('OK', $res));
    }

    /**
     * 查询项目延期确认配置列表
     * @param Request $request
     * @return Response
     */
    public function select(Request $request)
    {
        $projectId = $request->param()['param']['project_id'];
        $type = $request->param()['param']['type'];
        $stepCategoryId = $request->param()['param']['step_category_id'] ?? 0;
        $res = $this->projectStepCategoryConfirmConfigService->select($projectId, $type, $stepCategoryId);
        return json(success_response('OK', $res));
    }

    /**
     * 查询用户在项目里能确认的环节ID列表
     * @param Request $request
     * @return Response
     */
    public function userStepCategoryIdList(Request $request)
    {
        $projectId = $request->param()['param']['project_id'];
        $type = $request->param()['param']['type'];
        $res = $this->projectStepCategoryConfirmConfigService->getUserCanConfirmStepCategoryIdList($projectId, $request->getUserId(), $type);
        return json(success_response('OK', $res));
    }
}
